﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zor_Modes;
using Zor_IDAL;
using Zor_Tools;
using System.Data;
namespace Zor_DAL
{
    public class Zor_AnnualTask_DAL<T> where T : class
    {
        #region -年度计划任务管理 -
        /// <summary>
        /// 查询所有街道
        /// create zhl by 2017.3.27     
        /// </summary>
        /// <returns></returns>
        public static List<T> SelectStreet()
        {
            var sql = "select[Dt_Id],[Dt_Name] from [dbo].[Sys_Department] where Dt_Level =3";
            return DapperQuery<T>.DoQueryList(sql, null);
        }
      
        /// <summary>
        /// 年度计划任务管理-新增
        /// create zhl by 17.3.27
        /// </summary>
        /// <param name="task">年度计划任务对象</param>
        /// <returns>执行结果：1 成功 0失败</returns>
        public static BaseAnswer InsertAnnualTask(Zor_AnnualTask task)
        {              
               
            var sql = @"if not exists(select At_StreetName from [Zor_AnnualTask] where At_StreetName  =@At_StreetName ) 
                        insert into Zor_AnnualTask values 
                        (@At_Year,@At_StreetName ,@At_RegisteredPlan,@At_RevenuePlan,@At_CreateDate,@User_Id,@At_ModifyDate,@At_ModifyName,@At_Remarks)";
            BaseAnswer bar = DapperInsert<T>.DoInsert(sql, task);
            return bar;
        }

        /// <summary>
        /// 年度计划任务管理-修改
        /// create zhl by 17.3.27
        /// </summary>
        /// <param name="task">年度计划任务对象</param>
        /// <returns>执行结果：1 成功 0失败</returns>
        public static BaseAnswer UpdateAnnualTask(Zor_AnnualTask task)
        {
            
            var sql = "";
            sql = "update [Zor_AnnualTask] set At_Year=@At_Year,At_StreetName=@At_StreetName,At_RegisteredPlan=@At_RegisteredPlan,At_RevenuePlan=@At_RevenuePlan,At_ModifyDate=@At_ModifyDate,At_ModifyName=@At_ModifyName where At_Id = @At_Id";
            BaseAnswer bar = DapperEdit<T>.DoEdit(sql, task);
            return bar;
        }
        /// <summary>
        /// 删除年度计划任务
        /// create zhl by 17.3.27
        /// </summary>
        /// <param name="id">年度计划任务的id</param>
        /// <returns>1正常 返回0</returns>
        public static BaseAnswer DeleteAnnualTask(int[] id)
        {
          
            var sql = "";
            sql += "delete from  [Zor_AnnualTask]   where   At_Id in @At_Id";
            BaseAnswer bar = DapperDelete<T>.DoDelete(sql, new { At_Id = id.ToArray<int>() });
            return bar;
        }
        #endregion
    }
}
